package com.yida.gwj.deposit.service.impl;

import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.common.utils.GwjConvertUtil;
import com.yida.gwj.deposit.domain.GwjDepositBusinessOwner;
import com.yida.gwj.deposit.mapper.GwjDepositBusinessOwnerMapper;
import com.yida.gwj.deposit.service.IGwjDepositBusinessOwnerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 业务业主信息（缴存业务管理模块）Service业务层处理
 *
 * @author 缴存业务管理模块
 * @date 2023-01-11
 */
@Service
public class GwjDepositBusinessOwnerServiceImpl implements IGwjDepositBusinessOwnerService {
	@Resource
	private GwjDepositBusinessOwnerMapper gwjDepositBusinessOwnerMapper;

	/**
	 * 查询业务业主信息（缴存业务管理模块）
	 *
	 * @param bizOwnerId 业务业主信息（缴存业务管理模块）主键
	 * @return 业务业主信息（缴存业务管理模块）
	 */
	@Override
	public GwjDepositBusinessOwner selectGwjDepositBusinessOwnerByBizOwnerId(Long bizOwnerId) {
		return gwjDepositBusinessOwnerMapper.selectGwjDepositBusinessOwnerByBizOwnerId(bizOwnerId);
	}

	/**
	 * 查询业务业主信息（缴存业务管理模块）列表
	 *
	 * @param gwjDepositBusinessOwner 业务业主信息（缴存业务管理模块）
	 * @return 业务业主信息（缴存业务管理模块）
	 */
	@Override
	public List<GwjDepositBusinessOwner> selectGwjDepositBusinessOwnerList(GwjDepositBusinessOwner gwjDepositBusinessOwner) {
		return gwjDepositBusinessOwnerMapper.selectGwjDepositBusinessOwnerList(gwjDepositBusinessOwner);
	}

	/**
	 * 新增业务业主信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessOwner 业务业主信息（缴存业务管理模块）
	 * @return 结果
	 */
	@Override
	public int insertGwjDepositBusinessOwner(GwjDepositBusinessOwner gwjDepositBusinessOwner) {
		gwjDepositBusinessOwner.setCreateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gwjDepositBusinessOwner.setCreateTime(DateUtils.getNowDate());
		return gwjDepositBusinessOwnerMapper.insertGwjDepositBusinessOwner(gwjDepositBusinessOwner);
	}

	/**
	 * 新增业务业主信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessOwners 业务业主信息（缴存业务管理模块）
	 * @return 结果
	 */
	@Override
	public int insertBatchGwjDepositBusinessOwner(List<GwjDepositBusinessOwner> gwjDepositBusinessOwners) {
		return gwjDepositBusinessOwnerMapper.insertBatchGwjDepositBusinessOwner(gwjDepositBusinessOwners);
	}

	/**
	 * 修改业务业主信息（缴存业务管理模块）
	 *
	 * @param gwjDepositBusinessOwner 业务业主信息（缴存业务管理模块）
	 * @return 结果
	 */
	@Override
	public int updateGwjDepositBusinessOwner(GwjDepositBusinessOwner gwjDepositBusinessOwner) {
		gwjDepositBusinessOwner.setUpdateBy(SecurityUtils.getLoginUser().getSysUser().getRealName());
		gwjDepositBusinessOwner.setUpdateTime(DateUtils.getNowDate());
		return gwjDepositBusinessOwnerMapper.updateGwjDepositBusinessOwner(gwjDepositBusinessOwner);
	}

	/**
	 * 批量删除业务业主信息（缴存业务管理模块）
	 *
	 * @param bizOwnerIds 需要删除的业务业主信息（缴存业务管理模块）主键
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessOwnerByBizOwnerIds(Long[] bizOwnerIds) {
		return gwjDepositBusinessOwnerMapper.deleteGwjDepositBusinessOwnerByBizOwnerIds(bizOwnerIds);
	}

	/**
	 * 删除业务业主信息（缴存业务管理模块）信息
	 *
	 * @param bizOwnerId 业务业主信息（缴存业务管理模块）主键
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessOwnerByBizOwnerId(Long bizOwnerId) {
		return gwjDepositBusinessOwnerMapper.deleteGwjDepositBusinessOwnerByBizOwnerId(bizOwnerId);
	}

	/**
	 * 删除业务业主信息（缴存业务管理模块）信息
	 *
	 * @param bizId     业务ID
	 * @param houseCodes 房屋标识码
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessOwnerByBizIdAndHouseCodes(Long bizId, String[] houseCodes) {
		return gwjDepositBusinessOwnerMapper.deleteGwjDepositBusinessOwnerByBizIdAndHouseCodes(bizId,houseCodes);
	}

	/**
	 * 根据业务ID和房屋标识码查询业务业主信息（缴存业务管理模块）列表
	 *
	 * @param houseCode 房屋标识码
	 * @param bizId     业务ID
	 * @return 业务业主信息（缴存业务管理模块）集合
	 */
	@Override
	public GwjDepositBusinessOwner selectGwjDepositBusinessOwner(String houseCode, Long bizId) {
		GwjDepositBusinessOwner gwjDepositBusinessOwner = new GwjDepositBusinessOwner();
		gwjDepositBusinessOwner.setBizId(bizId);
		gwjDepositBusinessOwner.setHouseCode(houseCode);
		return gwjDepositBusinessOwnerMapper.selectGwjDepositBusinessOwner(gwjDepositBusinessOwner);
	}

	/**
	 * 通过业务ID查询业务业主信息（缴存业务管理模块）列表
	 *
	 * @param bizId 业务ID
	 * @return 业务业主信息（缴存业务管理模块）集合
	 */
	@Override
	public List<GwjDepositBusinessOwner> selectGwjDepositBusinessOwnerListByBizId(Long bizId) {
		GwjDepositBusinessOwner gwjDepositBusinessOwner = new GwjDepositBusinessOwner();
		gwjDepositBusinessOwner.setBizId(bizId);
		return gwjDepositBusinessOwnerMapper.selectGwjDepositBusinessOwnerList(gwjDepositBusinessOwner);
	}

	/**
	 * 通过业务ID删除业务业主信息（缴存业务管理模块）信息
	 *
	 * @param bizId 业务ID
	 * @return 结果
	 */
	@Override
	public int deleteGwjDepositBusinessOwnerByBizId(Long bizId) {
		return gwjDepositBusinessOwnerMapper.deleteGwjDepositBusinessOwnerByBizId(bizId);
	}

    @Override
    public boolean saveBatch(List<GwjDepositBusinessOwner> depositBusinessOwners) {
		GwjConvertUtil.partition(depositBusinessOwners,1000).forEach(item-> gwjDepositBusinessOwnerMapper.saveBatch(item));
		return true;
	}
}
